package com.wbdgj.ui.booking;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.google.gson.internal.LinkedTreeMap;
import com.wbdgj.R;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.base.BaseFragment;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnNoResponseListener;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.ui.home.MapDialogAtivity;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.views.RichTextView;

import java.text.DecimalFormat;

import butterknife.BindView;
import retrofit2.Call;

public class BookingInfo03Fragment extends BaseFragment {
    private Context context;


    @BindView(R.id.address)
    TextView address;
    private String COORDSX, COORDSY;
    private String branchName;
    @Override
    protected int getLayout() {
        return R.layout.ui_booking_info03;
    }

    @Override
    protected void onInit() {
        context = getActivity();
        hotel_info();
        findViewById(R.id.dh).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TextUtils.isEmpty(COORDSX)){
                    Uri uri = Uri.parse("amapuri://route/plan/?dlat="+""+"&dlon="+""+"&dname="+branchName+"&dev=0&t=0");
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                }else{
                    startActivity(new Intent(context, MapDialogAtivity.class).putExtra("COORDSX", COORDSX).putExtra("COORDSY", COORDSY));
                }
            }
        });
    }

    @Override
    public void fetchData() {

    }

    private void hotel_info() {
        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().hotel_info(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.HOTEL_ID));
        call01.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    address.setText("地址："+linkedTreeMap.get("branch_addr")+"");
                    branchName = linkedTreeMap.get("branch_name")+"";
                    if((linkedTreeMap.get("branch_coords")+"").contains(",")){
                        COORDSY = (linkedTreeMap.get("branch_coords")+"").split(",")[1];
                        COORDSX = (linkedTreeMap.get("branch_coords")+"").split(",")[0];
                    }
                }
            }
        });
    }
}
